/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import Controller.Materiel;
import Controller.Ordinateur;
import java.sql.Connection;
import java.sql.Statement;

/**
 *
 * @author Arthur
 */
public class OrdinateurDAO extends AbstractDAO<Ordinateur> {

  private MaterielDAO ordiDAO;

  public OrdinateurDAO(Connection connect) {
	super(connect);
	this.ordiDAO = new MaterielDAO(connect);
  }

  /**
   * Insertion d'un ordinateur
   * @param obj
   * @return true/false
   */
  @Override
  protected boolean insert(Ordinateur obj) {
	/**
	 * Insert le materiel + l'ordinateur
	 */
	try {
	  Statement stm = this.connect.createStatement();
	  Materiel mat = new Materiel(obj.getNumCB(), obj.getNumCompta(), obj.getNumSerie(), obj.getNom(), obj.getDescriptif(), obj.getDateHT(), obj.getPrixHT(), obj.getGarantie(), obj.getNumBC(), obj.getBudget(), obj.getAmortissement(), obj.getType(), obj.getFournisseur(), obj.getMarque(), obj.getSalle(), obj.getSecteur());
	  Boolean verifInsert = this.ordiDAO.insert(mat);

	  if (verifInsert) // 4..executer requete
	  {
		stm.executeUpdate("INSERT INTO ordinateur (numCB,numCompta,numSerie,nom,descriptif,dateHT,prixHT,garantie,numBC,budget,amortissement,idT,idF,idM,idS,idSc) VALUES ('" + obj.getNumCB() + "','" + obj.getNumCompta() + "','" + obj.getNumSerie() + "','" + obj.getNom() + "','" + obj.getDescriptif() + "','" + obj.getDateHT() + "','" + obj.getPrixHT() + "','" + obj.getGarantie() + "','" + obj.getNumBC() + "','" + obj.getBudget() + "','" + obj.getAmortissement() + "','" + obj.getType().getIdT() + "','" + obj.getFournisseur().getId() + "','" + obj.getMarque().getIdM() + "','" + obj.getSalle().getIdS() + "','" + obj.getSecteur().getId() + "');");
		stm.close();
	  }
	  return true;
	} catch (Exception e) {
	  e.printStackTrace();
	  return false;
	}
  }

  @Override
  protected boolean update(Ordinateur obj) {
	throw new UnsupportedOperationException("Not supported yet.");
  }

  @Override
  protected boolean delete(Ordinateur obj) {
	throw new UnsupportedOperationException("Not supported yet.");
  }

  @Override
  protected Ordinateur findById(int id) {
	throw new UnsupportedOperationException("Not supported yet.");
  }
}
